<?php
/**
 * DouPHP小程序模块
 * Author: cuihaifeng  qq 366131726 微信同号
 * 网址：www.zbxingke.com www.0533hf.com
 */
if (!defined('IN_DOUCO_API')) {
    die('Access Denied');
}

/**
 * 获取会员信息
 */
function doPageGet(){

    global $_GPC, $_W;

    $user_id = $_GPC['user_id']?$_GPC['user_id'] : get_user_by_openid(wxapp_getopenid());

    if(!$user_id){
        return wxapp_result(41009,'请登录');
    }
    $user = get_user($user_id);
    $user['add_time'] = date("Y-m-d", $user['add_time']);
    return wxapp_result(0,'success',$user);
}

/**
 * 更新个人资料
 */
function doPageUpdate(){
    global $_GPC, $_W,$_LANG,$check;

    $user_id = $_GPC['user_id']?$_GPC['user_id'] : get_user_by_openid(wxapp_getopenid());
    if(!$user_id){
        return wxapp_result(41009,'请登录');
    }
    $contact = $_GPC['contact'];
    $telphone = $_GPC['telphone'];
    $address = $_GPC['address'];
    //验证联系人信息
    if (!$check->is_telphone($telphone)) {
        return wxapp_result(404, $_LANG['user_telphone_cue']);
    }
    if (!$contact) {
        return wxapp_result(404, $_LANG['user_contact_empty']);
    } elseif ($check->is_illegal_char($contact)) {
        return wxapp_result(404, $_LANG['user_contact'] . $_LANG['illegal_char']);
    }
    // 验证地址
    if (!$address) {
        return wxapp_result(404, $_LANG['user_address_empty']);
    } elseif ($check->is_illegal_char($_POST['address'])) {
        return wxapp_result(404, $_LANG['user_address'] . $_LANG['illegal_char']);
    }
    pdo_update('user', array('contact' => $contact, 'telphone' => $telphone, 'address' => $address), array('user_id' => $user_id));
}